package com.ruoyi.system.controller;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketMovieType;
import com.ruoyi.system.service.ITicketMovieTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电影类别Controller
 * 
 * @author ruoyi
 * @date 2022-01-10
 */
@Controller
@RequestMapping("/system/ticketmovietype")
public class TicketMovieTypeController extends BaseController
{
    private String prefix = "system/ticketmovietype";

    @Autowired
    private ITicketMovieTypeService ticketMovieTypeService;

    @RequiresPermissions("system:ticketmovietype:view")
    @GetMapping()
    public String ticketmovietype()
    {
        return prefix + "/ticketmovietype";
    }

    /**
     * 查询电影类别列表
     */
    @RequiresPermissions("system:ticketmovietype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TicketMovieType ticketMovieType)
    {
        startPage();
        List<TicketMovieType> list = ticketMovieTypeService.selectTicketMovieTypeList(ticketMovieType);
        return getDataTable(list);
    }

    /**
     * 导出电影类别列表
     */
    @RequiresPermissions("system:ticketmovietype:export")
    @Log(title = "电影类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TicketMovieType ticketMovieType)
    {
        List<TicketMovieType> list = ticketMovieTypeService.selectTicketMovieTypeList(ticketMovieType);
        ExcelUtil<TicketMovieType> util = new ExcelUtil<TicketMovieType>(TicketMovieType.class);
        return util.exportExcel(list, "电影类别数据");
    }

    /**
     * 新增电影类别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电影类别
     */
    @RequiresPermissions("system:ticketmovietype:add")
    @Log(title = "电影类别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TicketMovieType ticketMovieType)
    {
        return toAjax(ticketMovieTypeService.insertTicketMovieType(ticketMovieType));
    }

    /**
     * 修改电影类别
     */
    @RequiresPermissions("system:ticketmovietype:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        TicketMovieType ticketMovieType = ticketMovieTypeService.selectTicketMovieTypeById(id);
        mmap.put("ticketMovieType", ticketMovieType);
        return prefix + "/edit";
    }

    /**
     * 修改保存电影类别
     */
    @RequiresPermissions("system:ticketmovietype:edit")
    @Log(title = "电影类别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TicketMovieType ticketMovieType)
    {
        return toAjax(ticketMovieTypeService.updateTicketMovieType(ticketMovieType));
    }

    /**
     * 删除电影类别
     */
    @RequiresPermissions("system:ticketmovietype:remove")
    @Log(title = "电影类别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketMovieTypeService.deleteTicketMovieTypeByIds(ids));
    }

    //获取电影类型列表
    @GetMapping("/getMovieTypeList")
    @ResponseBody
    public AjaxResult getMovieTypeList(TicketMovieType ticketMovieYear)
    {
        List<TicketMovieType> list = this.ticketMovieTypeService.selectTicketMovieTypeList(ticketMovieYear);
        AjaxResult result = new AjaxResult();
        JSONArray array = new JSONArray();
        for(TicketMovieType item : list)
        {
            array.add(item.getTypeName());
        }
        result.put("array", array);
        return result;
    }
}
